package com.mlz.mlzmall.ui.activity.act.main;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.JsonRequest;
import com.google.gson.Gson;
import com.mlz.mlzmall.R;
import com.mlz.mlzmall.bean.GetAwardPromotionResponse;
import com.mlz.mlzmall.bean.GetMyPromotionResponse;
import com.mlz.mlzmall.bean.GetSharePromotionResponse;
import com.mlz.mlzmall.bean.Shareover;
import com.mlz.mlzmall.ui.activity.act.base.BaseActivity;
import com.mlz.mlzmall.ui.activity.act.base.BaseUiListener;
import com.mlz.mlzmall.ui.activity.act.personal.myActivityPack.ActionActivity;
import com.mlz.mlzmall.ui.activity.act.personal.userLogin.LoginActivity;
import com.mlz.mlzmall.ui.utils.mlz.ConfigInfo;
import com.mlz.mlzmall.ui.utils.mlz.Constans;
import com.mlz.mlzmall.ui.utils.mlz.DialogView;
import com.mlz.mlzmall.ui.utils.util.ACache;
import com.mlz.mlzmall.ui.utils.util.LogUtils;
import com.mlz.mlzmall.ui.utils.util.SharedUtils;
import com.sina.weibo.sdk.api.WebpageObject;
import com.sina.weibo.sdk.api.WeiboMultiMessage;
import com.sina.weibo.sdk.api.share.BaseResponse;
import com.sina.weibo.sdk.api.share.IWeiboHandler;
import com.sina.weibo.sdk.api.share.IWeiboShareAPI;
import com.sina.weibo.sdk.api.share.SendMultiMessageToWeiboRequest;
import com.sina.weibo.sdk.api.share.WeiboShareSDK;
import com.sina.weibo.sdk.auth.Oauth2AccessToken;
import com.sina.weibo.sdk.auth.sso.SsoHandler;
import com.sina.weibo.sdk.constant.WBConstants;
import com.tencent.connect.share.QQShare;
import com.tencent.mm.sdk.modelmsg.SendMessageToWX;
import com.tencent.mm.sdk.modelmsg.WXMediaMessage;
import com.tencent.mm.sdk.modelmsg.WXWebpageObject;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.tencent.tauth.Tencent;
import org.json.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * describe :
 * Created by Pm on 2016/5/27.
 * PackageName com.mlz.mlzmall.ui.activity.act.main.
 * ProjectName mlzmall_android.
 */

public class ShareActivity extends BaseActivity implements IWeiboHandler.Response{
    private RelativeLayout iv_back_share_activity;
    private WebView wv_share_out_login;
    public static final String IS_LOGIN = "IS_LOGIN";
    private TextView tv_share_title;//分享的后台标题
    private LinearLayout btn_no_login_share;
    private Button btn_get_now;
    private LinearLayout ll_login_no_share;
    private Button btn_go_login;
    private Button btn_go_bye;
    String shareId;
    private ScrollView rl_unjoin;
    private String ifjoin;
    private Button btn_share_friend;
    private ImageView iv_share_picture;
    private TextView tv_news_product;
    private TextView tv_news_explain;
    private TextView tv_time_first;
    private TextView tv_time_last;
    private String finish;
    private String finishtwo;
    private boolean isHaveImage;

    BaseUiListener baseUiListener;

    private ImageView iv_red;//蓝色图片
    private ImageView iv_gray;//灰色图片
    private ImageView iv_blue_over;
    private ImageView btn_finish_over;

    String shareurl;
    String shareimage;
    String sharetitle;
    String sharecontent;
    String sharemsg;

    private RelativeLayout rl_share_dialog;
    private RelativeLayout rl_weichat;
    private RelativeLayout rl_wei_friend;
    private RelativeLayout rl_qq_share;
    private RelativeLayout rl_weibo_share;
    private Button btn_cancal_share;
    private Tencent mTencent;
    private TextView dialog_body;
    private RelativeLayout rl_share_lv;
    String sharemags;

    ListView lv_share;

    String status2;
    int state;

    private ImageView btn_unfinish;
    private TextView tv_finish, tv_status;
    private Button btn_finish;
    private TextView tv_progress;
    private TextView tv_requireShareTimes;
    private RelativeLayout rl_activity_share;
    private LinearLayout progressBar_ll;
    private IWXAPI wxApi;
    private TextView tv_time_over;
    private TextView tv_time_text;
    private Oauth2AccessToken mAccessToken;
    private SsoHandler mSsoHandler;
    private IWeiboShareAPI mWeiboShareAPI;
    private GetSharePromotionResponse.SharePromotionDto sharePromotionDto;
    public List<GetSharePromotionResponse.SharePromotionDto.ProgressDetail> sharelist;
    public List<GetMyPromotionResponse.PageableDto.MyPromotionDto> pomitionlists;

    private int shareType;
    private int manufacturerId;
    private int promotionId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share);
//        init();
//        initView();
//        initListener();
//        initData();
    }

    @Override
    public void onResponse(BaseResponse baseResponse) {

    }


//    private void init() {
//        //获取manufacturerId
//        manufacturerId = Integer.parseInt(String.valueOf(SharedUtils.get(ShareActivity.this, "manufacturerId", 0)));
//        promotionId = Integer.parseInt(String.valueOf(SharedUtils.get(ShareActivity.this, "promotionId", 0)));
//
//        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//        mTencent = Tencent.createInstance(Constans.QQAPP_ID, this.getApplicationContext());
//        wxApi = WXAPIFactory.createWXAPI(this, Constans.APP_ID, false);
//        wxApi.registerApp(Constans.APP_ID);
//
//        mWeiboShareAPI = WeiboShareSDK.createWeiboAPI(ShareActivity.this, Constans.APP_KEY);
//        mWeiboShareAPI.registerApp();
//        Intent intent = getIntent();
//        state = intent.getIntExtra("State", 100);
//    }
//
//    private void initView() {
//        iv_back_share_activity = (RelativeLayout) findViewById(R.id.iv_back_share_activity);
//        wv_share_out_login = (WebView) findViewById(R.id.wv_share_out_login);
//        tv_share_title = (TextView) findViewById(R.id.tv_share_title);
//        btn_no_login_share = (LinearLayout) findViewById(R.id.btn_no_login_share);//已购买请登录按钮
//        ll_login_no_share = (LinearLayout) findViewById(R.id.ll_login_no_share);//没登陆的时候下面显示的按钮
//        btn_get_now = (Button) findViewById(R.id.btn_get_now);//登陆后下面显示的按钮
//        rl_unjoin = (ScrollView) findViewById(R.id.rl_unjoin);//可以分享时界面的状态显示
//        btn_share_friend = (Button) findViewById(R.id.btn_share_friend);//分享好友的功能
//        iv_share_picture = (ImageView) findViewById(R.id.iv_share_picture);//分享出去的图片
//        tv_news_product = (TextView) findViewById(R.id.tv_news_product);//分享产品的介绍
//        tv_news_explain = (TextView) findViewById(R.id.tv_news_explain);//分享产品的介绍
//        tv_time_first = (TextView) findViewById(R.id.tv_time_first);//分享活动期限的初始时间
//        tv_time_last = (TextView) findViewById(R.id.tv_time_last);//分享活动期限的末尾时间
//
//        rl_activity_share = (RelativeLayout) findViewById(R.id.rl_activity_share);//活动界面进入分享界面
//        progressBar_ll = (LinearLayout) findViewById(R.id.progressBar_ll);
//
//        tv_requireShareTimes = (TextView) findViewById(R.id.tv_requireShareTimes);//比例
//        tv_progress = (TextView) findViewById(R.id.tv_progress);//比例
//
//        btn_unfinish = (ImageView) findViewById(R.id.btn_unfinish);//未完成
//        tv_finish = (TextView) findViewById(R.id.tv_finish);//未完成
//        tv_status = (TextView) findViewById(R.id.tv_status);
//        btn_finish = (Button) findViewById(R.id.btn_finish);//未完成
//        iv_red = (ImageView) findViewById(R.id.iv_red);//初始化蓝色图片
//        iv_gray = (ImageView) findViewById(R.id.iv_gray);//初始化灰色图片
//        iv_blue_over = (ImageView) findViewById(R.id.iv_blue_over);
//        btn_finish_over = (ImageView) findViewById(R.id.btn_finish_over);
//        rl_share_dialog = (RelativeLayout) findViewById(R.id.rl_share_dialog);//分享框
//        rl_weichat = (RelativeLayout) findViewById(R.id.rl_weichat);//微信分享的初始化
//        rl_wei_friend = (RelativeLayout) findViewById(R.id.rl_wei_friend);//微信朋友圈分享的初始化
//        rl_qq_share = (RelativeLayout) findViewById(R.id.rl_qq_share);//扣扣分享的初始化
//        rl_weibo_share = (RelativeLayout) findViewById(R.id.rl_weibo_share);//微博分享的初始化
//        btn_cancal_share = (Button) findViewById(R.id.btn_cancal_share);//分享取消按钮的初始化
//
////        tv_time_over = (TextView) findViewById(R.id.tv_time_over);
////        tv_time_text = (TextView) findViewById(R.id.tv_time_text);
//
//    }
//
//    private void initListener() {
//        iv_back_share_activity.setOnClickListener(onclicklistener);
//
//    }
//
//    private void initData() {
//        getshareData2();
//
//    }
//
//    public void getshareData() {
//        ///
//        //   JSONObject jsonObject = new JSONObject(getMall());
//        JsonRequest jsonRequest = new JsonObjectRequest(Request.Method.GET, "http://app.mlzmall.com/api/promotion/sharePromotion?promotionId=" + promotionId, null, new Response.Listener<JSONObject>() {
//            @Override
//            public void onResponse(JSONObject jsonObject) {
//                LogUtils.d("sharePromotion?promotionId：" + jsonObject.toString());
//                Gson gson = new Gson();
//                GetSharePromotionResponse bean = gson.fromJson(jsonObject.toString(), GetSharePromotionResponse.class);
//                if (bean.getData() != null) {
//                    sharePromotionDto = bean.getData();
//                    sharelist = bean.getData().getProgressDetails();
//                    // 用户名
//                     int type = sharePromotionDto.getType();
//                     String url = sharePromotionDto.getShareDescriptionUrl();
//                    if (null != sharePromotionDto.productIds) {
//                        int nums = sharePromotionDto.productIds.size();//获取数组的长度
//                        shareId = sharePromotionDto.productIds.get(nums - 1);//获取数组最后一个索引的数字
//                    }
//                    ifjoin = sharePromotionDto.getStatus();//分享状态
//                    finish = sharePromotionDto.getGiftReceive();
//                    //返回的数据判断是否完成
//
//                    shareurl =sharePromotionDto.getShare().getUrl();//分享的url
//                    shareimage = sharePromotionDto.getShare().getImage();//分享的图片
//                    sharetitle = sharePromotionDto.getShare().getTitle();//分享的标题
//                    sharecontent = sharePromotionDto.getShare().getContent();//分享的产品详情
//                     String shareproduct = sharePromotionDto.getImage();//分享出去的图片
//                     String productmessage = sharePromotionDto.getMessage();//分享产品的介绍
//                     String puroductdescribe = sharePromotionDto.getDescribe();//分享产品的介绍
//
//                     int progress =sharePromotionDto.getProgress();
//                     int requireShareTimes = sharePromotionDto.getRequireShareTimes();
//
//                    //初始时间
//                    Date dat_start = new Date(sharePromotionDto.getDateStart());
//                    //结束时间
//                    Date dat_end = new Date(sharePromotionDto.getDateEnd());
//                    GregorianCalendar ge = new GregorianCalendar();
//                    GregorianCalendar end = new GregorianCalendar();
//                    ge.setTime(dat_start);
//                    end.setTime(dat_end);
//                    SimpleDateFormat formatend = new SimpleDateFormat("yyyy-MM-dd");
//                    String datastart = formatend.format(ge.getTime());
//                    String datasend = formatend.format(end.getTime());
//
//                    String title = sharePromotionDto.getTitle();
//
//                    //更新UI
//                    updateCustomInfoLayout(url, shareproduct, productmessage, puroductdescribe, datastart, datasend, progress, requireShareTimes, type, title, sharemsg, sharelist, pomitionlists);
//                    progressBar_ll.setVisibility(View.GONE);
//
//                }
//
//            }
//        }, new Response.ErrorListener() {
//            @Override
//            public void onErrorResponse(VolleyError error) {
//                Log.e("getshareData", error.getMessage(), error);
//
//            }
//        }) {
//            @Override
//            public Map<String, String> getHeaders() throws AuthFailureError {
//                Map<String, String> map = new HashMap<String, String>();
//                map.put(ConfigInfo.CHARSET, ConfigInfo.UTF8);
//                map.put(ConfigInfo.COOKIE, ConfigInfo.COOKIE_KEY + sessionId);
//                map.put(ConfigInfo.TYPE, ConfigInfo.TYPE_KEY);
//                return map;
//            }
//        };
//
//        // 设置该请求的标签
//        jsonRequest.setTag("getshareData");
//        // 将请求添加到队列中
//        ((MyApplication) getApplication()).getRequestQueue().add(jsonRequest);
//    }
//
//    public void getshareData2() {
//        JsonRequest jsonRequest = new JsonObjectRequest(Request.Method.GET, "http://app.mlzmall.com/api/promotion/myPromotionList", null, new Response.Listener<JSONObject>() {
//            @Override
//            public void onResponse(JSONObject jsonObject) {
//                LogUtils.d("promotion/myPromotionList:" + jsonObject.toString());
//                Gson gson = new Gson();
//                GetMyPromotionResponse bean = gson.fromJson(jsonObject.toString(), GetMyPromotionResponse.class);
//                pomitionlists = bean.getData().getList();
//                getshareData3();
//            }
//        }, new Response.ErrorListener() {
//            @Override
//            public void onErrorResponse(VolleyError error) {
//                Log.e("getshareData2", error.getMessage(), error);
//
//            }
//        }) {
//            @Override
//            public Map<String, String> getHeaders() throws AuthFailureError {
//                Map<String, String> map = new HashMap<String, String>();
//                map.put(ConfigInfo.CHARSET, ConfigInfo.UTF8);
//                map.put(ConfigInfo.COOKIE, ConfigInfo.COOKIE_KEY + sessionId);
//                map.put(ConfigInfo.TYPE, ConfigInfo.TYPE_KEY);
//                return map;
//            }
//        };
//
//        // 设置该请求的标签
//        jsonRequest.setTag("getshareData2");
//        // 将请求添加到队列中
//        ((MyApplication) getApplication()).getRequestQueue().add(jsonRequest);
//    }
//
//    public void getshareData3() {
//        JsonRequest jsonRequest = new JsonObjectRequest(Request.Method.GET, "http://app.mlzmall.com/api/promotion/awardPromotion?promotionId=" + promotionId, null, new Response.Listener<JSONObject>() {
//            @Override
//            public void onResponse(JSONObject jsonObject) {
//                LogUtils.d("promotion/myPromotionList:" + jsonObject.toString());
//                Gson gson = new Gson();
//                GetAwardPromotionResponse bean = gson.fromJson(jsonObject.toString(), GetAwardPromotionResponse.class);
//                status2 = bean.getData().getStatus2();
//                finishtwo = bean.getData().getGiftReceive();
//                getshareData();
//
//            }
//        }, new Response.ErrorListener() {
//            @Override
//            public void onErrorResponse(VolleyError error) {
//                Log.e("getshareData3", error.getMessage(), error);
//
//            }
//        }) {
//            @Override
//            public Map<String, String> getHeaders() throws AuthFailureError {
//                Map<String, String> map = new HashMap<String, String>();
//                map.put(ConfigInfo.CHARSET, ConfigInfo.UTF8);
//                map.put(ConfigInfo.COOKIE, ConfigInfo.COOKIE_KEY + sessionId);
//                map.put(ConfigInfo.TYPE, ConfigInfo.TYPE_KEY);
//                return map;
//            }
//        };
//
//        // 设置该请求的标签
//        jsonRequest.setTag("getshareData3");
//        // 将请求添加到队列中
//        ((MyApplication) getApplication()).getRequestQueue().add(jsonRequest);
//    }
//    private void updateCustomInfoLayout(final String url, final String shareproduct, String productmessage, String puroductdescribe, String datastart, String datasend, int progress, int requireShareTimes, final int type, final String title, final String sharemsg, final List sharelist, final List pomitionlists) {
//        //如果登录的话
//        if (MyApplication.getInstance().isLogin()) {
//            //从主界面跳转过来
//            if (StringTools.shareid == 6) {
//
//                if (status2.equals("JOINED")) {
//                    rl_activity_share.setVisibility(View.VISIBLE);
//                    rl_unjoin.setVisibility(View.VISIBLE);
//                    btn_share_friend.setVisibility(View.VISIBLE);//分享好友的按钮
//                    tv_share_title.setText("活动进度");//显示标题
//                    imageLoader.displayImage(shareproduct, iv_share_picture, options);//分享商品的图片
//                    tv_news_product.setText(productmessage);//分享产品的介绍
//                    tv_news_explain.setText(puroductdescribe);//分享产品的介绍
//                    tv_time_first.setText(datastart);
//                    tv_time_last.setText(datasend);
//                    tv_progress.setText(String.valueOf(progress));
//                    tv_requireShareTimes.setText(String.valueOf(requireShareTimes));
//
//                    if (sharelist != null) {
//                        lv_share = (ListView) findViewById(R.id.lv_share);
//                        lv_share.setAdapter(new MyAdapter());
//                        setListViewHeightBasedOnChildren(lv_share);
//                    }
//
//                    if (pomitionlists != null) {
//                        System.out.println("******++++"+state);
//                        if (state == 1) {
//                            tv_finish.setText("0%");
//                            tv_finish.setTextColor(Color.rgb(83,203,199));
//                            btn_unfinish.setVisibility(View.VISIBLE);
//                            tv_status.setText("已过期");
//                            iv_gray.setVisibility(View.VISIBLE);
//
//                        } else if (state == 2 ||state == 3 ||state == 4) {
//
//                            tv_finish.setTextColor(Color.rgb(83,203,199));
//                            tv_finish.setText("0%");
//                            iv_gray.setVisibility(View.VISIBLE);
//                            btn_unfinish.setVisibility(View.VISIBLE);
//                            tv_status.setText("未完成");
//                        }else if(state == 5){
//                            tv_finish.setText("100%");
//                            iv_red.setVisibility(View.VISIBLE);
//                            btn_finish.setVisibility(View.VISIBLE);
//
//                        }else if(state == 6 || state == 7){
//                            tv_finish.setText("100%");
//                            iv_blue_over.setVisibility(View.VISIBLE);
//                            btn_finish_over.setVisibility(View.VISIBLE);
//                            tv_status.setText("已领取");
//                        }
//                        else {
//
//                            if(sharePromotionDto.getGiftReceive().equals("true")){
//                                tv_finish.setText("100%");
//                                btn_finish_over.setVisibility(View.VISIBLE);
//                                iv_blue_over.setVisibility(View.VISIBLE);
//                                tv_status.setText("已领取");
//                            }else {
//                                tv_finish.setText("0%");
//                                btn_finish.setVisibility(View.VISIBLE);
//                                iv_red.setVisibility(View.VISIBLE);
//                            }
//
//                        }
//                    }
//
//                } else {
//                    tv_share_title.setText("分享有礼");//显示标题
//                    wv_share_out_login.setVisibility(View.VISIBLE);
//                    wv_share_out_login.getSettings().setJavaScriptEnabled(true);//webview的适配
//                    wv_share_out_login.loadUrl(url);//登录状态
//
//                    btn_get_now.setVisibility(View.VISIBLE);//登陆上后显示的按钮
//                    btn_get_now.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View v) {
//                            Intent intent = new Intent();
//                            intent.setClass(ShareActivity.this, GoogDetailsActivity.class);
//                            intent.putExtra("productId",Integer.valueOf(shareId));
//                            startActivity(intent);
//                        }
//                    });
//
//
//                }
//                //从登录界面跳转过来
//            } else if (StringTools.shareid == 4) {
//                tv_share_title.setText("分享有礼");//显示标题
//                wv_share_out_login.setVisibility(View.VISIBLE);
//                wv_share_out_login.getSettings().setJavaScriptEnabled(true);//webview的适配
//                wv_share_out_login.loadUrl(url);//登录状态
//
//                btn_get_now.setVisibility(View.VISIBLE);//登陆上后显示的按钮
//                btn_get_now.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        Intent intent = new Intent();
//                        intent.setClass(ShareActivity.this, GoogDetailsActivity.class);
//                        intent.putExtra("productId",Integer.valueOf(shareId));
//                        startActivity(intent);
//                    }
//                });
//                //从我的活动界面跳转过来
//            } else if (StringTools.shareid == 5) {
//                rl_activity_share.setVisibility(View.VISIBLE);
//                if (ifjoin.equals("UNJOINED") || ifjoin.equals("JOINED")) {
//                    rl_unjoin.setVisibility(View.VISIBLE);
//                    btn_share_friend.setVisibility(View.VISIBLE);//分享好友的按钮
//                    tv_share_title.setText("活动进度");//显示标题
//                    imageLoader.displayImage(shareproduct, iv_share_picture, options);//分享商品的图片
//                    tv_news_product.setText(productmessage);//分享产品的介绍
//                    tv_news_explain.setText(puroductdescribe);//分享产品的介绍
//                    tv_time_first.setText(datastart);
//                    tv_time_last.setText(datasend);
//                    tv_progress.setText(String.valueOf(progress));
//                    tv_requireShareTimes.setText(String.valueOf(requireShareTimes));
//
//                    if (sharelist != null) {
//                        lv_share = (ListView) findViewById(R.id.lv_share);
//                        lv_share.setAdapter(new MyAdapter());
//                        setListViewHeightBasedOnChildren(lv_share);    //让Scollview 和listview同时滑动
//                    }
//                    if (pomitionlists != null) {
//                        System.out.println("******@@@@@@"+state);
//                        if (state == 1) {
//                            tv_finish.setTextColor(Color.rgb(83,203,199));
//                            tv_finish.setText("0%");
//                            btn_unfinish.setVisibility(View.VISIBLE);
//                            tv_status.setText("已过期");
//                            iv_gray.setVisibility(View.VISIBLE);
//
//                        } else if (state == 2 ||state == 3 ||state == 4) {
//                            tv_finish.setTextColor(Color.rgb(83,203,199));
//                            tv_finish.setText("0%");
//                            btn_unfinish.setVisibility(View.VISIBLE);
//                            tv_status.setText("未完成");
//                            iv_gray.setVisibility(View.VISIBLE);
//                        }else if(state == 5){
//                            if(sharePromotionDto.getGiftReceive().equals("true")){
//                                tv_finish.setText("100%");
//                                btn_finish_over.setVisibility(View.VISIBLE);
//                                iv_blue_over.setVisibility(View.VISIBLE);
//                                tv_status.setText("已领取");
//                            }else {
//                                tv_finish.setText("100%");
//                                btn_finish.setVisibility(View.VISIBLE);
//                                iv_red.setVisibility(View.VISIBLE);
//                            }
//                        }else if(state == 6 || state == 7){
//                            tv_finish.setText("100%");
//                            btn_finish_over.setVisibility(View.VISIBLE);
//                            iv_blue_over.setVisibility(View.VISIBLE);
//                            tv_status.setText("已领取");
//                        }
//                    }
//                } else if (ifjoin.equals("EXPIRED")) {
//                    Button btn_share_over = (Button) findViewById(R.id.btn_share_over);
//                    btn_share_over.setVisibility(View.VISIBLE);
//                    tv_share_title.setText("活动进度");//显示标题
//                    imageLoader.displayImage(shareproduct, iv_share_picture, options);//分享商品的图片
//                    tv_news_product.setText(productmessage);//分享产品的介绍
//                    tv_news_explain.setText(puroductdescribe);//分享产品的介绍
//                    tv_time_first.setText(datastart);
//                    tv_time_last.setText(datasend);
//                    tv_progress.setText(String.valueOf(progress));
//                    tv_requireShareTimes.setText(String.valueOf(requireShareTimes));
//
//                    if (pomitionlists != null) {
////                        pomitionlists.get(pomitionstate) == 5;
//                        if (state == 4) {
//                            tv_finish.setText("100%");
//                            if (finish.equals("true")) {
//                                btn_finish_over.setVisibility(View.VISIBLE);
//                                iv_blue_over.setVisibility(View.VISIBLE);
//                            } else if (finish.equals("false")) {
//                                btn_finish.setVisibility(View.VISIBLE);
//                                iv_red.setVisibility(View.VISIBLE);
//                            }
//                        } else if (state == 5) {
//                            tv_finish.setText("100%");
//                            tv_finish.setTextColor(Color.rgb(83, 203, 199));
//                            btn_unfinish.setVisibility(View.VISIBLE);
//                            iv_gray.setVisibility(View.VISIBLE);
//                        } else {
//                            int number = progress / requireShareTimes;//显示百分号数
//                            if (number == 0) {
//                                tv_finish.setTextColor(Color.rgb(83,203,199));
//                                tv_finish.setText("0%");
//                                btn_unfinish.setVisibility(View.VISIBLE);
//                                iv_gray.setVisibility(View.VISIBLE);
//                            } else {
//                                tv_finish.setText("100%");
//                                if (finish.equals("true")) {
//                                    btn_finish_over.setVisibility(View.VISIBLE);
//                                    iv_blue_over.setVisibility(View.VISIBLE);
//                                } else if (finish.equals("false")) {
//                                    btn_finish.setVisibility(View.VISIBLE);
//                                    iv_red.setVisibility(View.VISIBLE);
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//            //如果没登陆的话
//        } else {
//            tv_share_title.setText("分享有礼");//显示标题
//            wv_share_out_login.setVisibility(View.VISIBLE);
//            wv_share_out_login.getSettings().setJavaScriptEnabled(true);//webview的适配
//            wv_share_out_login.loadUrl(url);//登录状态
//
//            rl_activity_share.setVisibility(View.VISIBLE);
//            ll_login_no_share.setVisibility(View.VISIBLE);//没登陆上显示的按钮
//            btn_go_login = (Button) findViewById(R.id.btn_go_login);//已购买请登录
//            btn_go_bye = (Button) findViewById(R.id.btn_go_buy);//登录直接去购买
//            btn_go_login.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    Intent intent = new Intent();
//                    intent.setClass(ShareActivity.this, LoginActivity.class);
//                    startActivity(intent);
//                }
//            });
//            btn_go_bye.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    Intent intent = new Intent();
//                    intent.setClass(ShareActivity.this, GoogDetailsActivity.class);
//                    intent.putExtra("productId",Integer.valueOf(shareId));
//                    startActivity(intent);
//                    finish();
//                }
//            });
//        }
//        btn_finish.setOnClickListener(new View.OnClickListener() {//点击兑换赠品传参数
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(ShareActivity.this, ActionActivity.class);
//                intent.putExtra("imageurl",shareproduct);
//                intent .putExtra("type", type);
//                intent.putExtra("promotionId", promotionId);
//                intent.putExtra("state2",state);
//                startActivity(intent);
//                PopupMenu popupMenu = new PopupMenu(ShareActivity.this, btn_finish);
//            }
//        });
//        //点击弹出分享界面
//        btn_share_friend.setOnClickListener(new View.OnClickListener() {//分享点击
//            @Override
//            public void onClick(View v) {
//
//                if (MyApplication.getInstance().isLogin()) {
//                    //进行分享的逻辑
//
//                    rl_share_dialog.setVisibility(View.VISIBLE);
//                    rl_weichat.setOnClickListener(new View.OnClickListener() {//微信分享
//                        @Override
//                        public void onClick(View v) {
//                            shareType = 1;
//                            StringTools.TYPE = 100;
//                            wechatShare(0);//分享到微信好友
//                            rl_share_dialog.setVisibility(View.GONE);
//                        }
//                    });
//
//                    rl_qq_share.setOnClickListener(new View.OnClickListener() {//扣扣分享的点击功能
//                        @Override
//                        public void onClick(View v) {
//                            shareType = 3;
//                            rl_share_dialog.setVisibility(View.GONE);
//                            final Bundle params = new Bundle();
//                            params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
//                            params.putString(QQShare.SHARE_TO_QQ_TITLE, sharetitle);
//                            params.putString(QQShare.SHARE_TO_QQ_SUMMARY, sharecontent);
//                            params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, shareurl);
//                            params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, shareimage);
//                            baseUiListener = new BaseUiListener();
//                            mTencent.shareToQQ(ShareActivity.this, params, baseUiListener);
//
//
//                        }
//                    });
//
//
//                    rl_wei_friend.setOnClickListener(new View.OnClickListener() {//朋友圈分享
//                        @Override
//                        public void onClick(View v) {
//                            shareType = 2;
//                            StringTools.TYPE = 100;
//                            wechatShare(1);//分享到微信朋友圈
//                            rl_share_dialog.setVisibility(View.GONE);
//                        }
//                    });
//
//                    rl_weibo_share.setOnClickListener(new View.OnClickListener() {//微博分享
//                        @Override
//                        public void onClick(View v) {
//                            shareType = 4;
//                            mWeiboShareAPI.handleWeiboResponse(getIntent(), ShareActivity.this);
//                            new Thread(new Runnable() {
//                                @Override
//                                public void run() {
//                                    WeiboMultiMessage weiboMessage = new WeiboMultiMessage();
//                                    // 用户可以分享其它媒体资源（网页、音乐、视频、声音中的一种）
//                                    weiboMessage.mediaObject = getWebpageObj();
//                                    // 2. 初始化从第三方到微博的消息请求
//                                    SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
//                                    // 用transaction唯一标识一个请求
//                                    request.transaction = String.valueOf(System.currentTimeMillis());
//                                    request.multiMessage = weiboMessage;
//                                    // 3. 发送请求消息到微博，唤起微博分享界面
//                                    mWeiboShareAPI.sendRequest(request);
//                                }
//                            }).start();
//
//                            rl_share_dialog.setVisibility(View.GONE);
//
//                        }
//                    });
//                    btn_cancal_share.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View v) {
//                            rl_share_dialog.setVisibility(View.GONE);
//                        }
//                    });
//
//                } else {
//                    //没登陆的话就到登陆界面
//                    Intent intent = new Intent();
//                    intent.setClass(ShareActivity.this, LoginActivity.class);
//                    startActivity(intent);
//                }
//            }
//        });
//    }
//    @Override
//    public void onClick(View v) {
//
//    }
//
//    public View.OnClickListener onclicklistener = new View.OnClickListener() {
//        @Override
//        public void onClick(View v) {
//            switch (v.getId()) {
//                case R.id.iv_back_share_activity:
//                    if (StringTools.shareid == 6) {
//                        Intent intent0 = new Intent(ShareActivity.this, MainActivity.class);
//                        startActivity(intent0);
//                    }
//                    finish();
//                    overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
//                default:
//                    break;
//            }
//        }
//    };
//    private void setListViewHeightBasedOnChildren(ListView lv_share) {
//        // 获取ListView对应的Adapter
//        ListAdapter listAdapter = lv_share.getAdapter();
//        if (listAdapter == null) {
//            return;
//        }
//        int totalHeight = 0;
//        for (int i = 0; i < listAdapter.getCount(); i++) {
//            // listAdapter.getCount()返回数据项的数目
//            View listItem = listAdapter.getView(i, null, lv_share);
//            // 计算子项View 的宽高
//            listItem.measure(0, 0);
//            if (i == listAdapter.getCount() - 1 && isHaveImage) {
//                totalHeight += listItem.getMeasuredHeight() + 55;
//                break;
//            }
//            // 统计所有子项的总高度
//            totalHeight += (listItem.getMeasuredHeight() + lv_share.getDividerHeight()) + 5;
//        }
//
//        ViewGroup.LayoutParams params = lv_share.getLayoutParams();
//        params.height = totalHeight + (lv_share.getDividerHeight() * listAdapter.getCount());
//        // listView.getDividerHeight()获取子项间分隔符占用的高度
//        // params.height最后得到整个ListView完整显示需要的高度
//        lv_share.setLayoutParams(params);
//
//    }
//
//    @Override
//    public void onResponse(BaseResponse baseResponse) {
//        switch (baseResponse.errCode) {
//            case WBConstants.ErrorCode.ERR_OK:
//                Toast.makeText(ShareActivity.this, "分享返回", Toast.LENGTH_LONG)
//                        .show();
//                shareSuccese(new MyHandler(),getApplication());
//                break;
//            case WBConstants.ErrorCode.ERR_CANCEL:
//                break;
//            case WBConstants.ErrorCode.ERR_FAIL:
//                Toast.makeText(ShareActivity.this, "分享失败", Toast.LENGTH_LONG)
//                        .show();
//                break;
//            default:
//                break;
//        }
//
//    }
//
//    private class MyAdapter extends BaseAdapter {
//
//        @Override
//        public int getCount() {
//            return sharelist.size();
//        }
//
//
//        @Override
//        public Object getItem(int position) {
//            return sharelist.get(position);
//        }
//
//        @Override
//        public long getItemId(int position) {
//            return 0;
//        }
//
//        @Override
//        public View getView(int position, View convertView, ViewGroup parent) {
//            convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.share_list_name, null);
//            ViewHolder vh = new ViewHolder();
//            vh.tv_time_text = (TextView) convertView.findViewById(R.id.tv_time_text);
//            vh.tv_time_over = (TextView) convertView.findViewById(R.id.tv_time_over);
//
//            if (sharelist != null) {
//                vh.tv_time_text.setText(sharelist.get(position).getMsg());
//
//
//                //将后台的long型开始时间转换为正常日期并显示
//                Date dat_start = new Date(sharelist.get(position).getDate());
//                java.util.GregorianCalendar gc = new java.util.GregorianCalendar();
//                gc.setTime(dat_start);
//                SimpleDateFormat formatstart = new SimpleDateFormat("yyyy-MM-dd");
//                String sb = formatstart.format(gc.getTime());
//                vh.tv_time_over.setText(sb);
//            }
//            return convertView;
//        }
//
//        class ViewHolder {
//            TextView tv_time_text;
//            TextView tv_time_over;
//        }
//    }
//    /**
//     * 微信分享 （这里仅提供一个分享网页的示例，其它请参看官网示例代码）
//     *
//     * @param flag(0:分享到微信好友，1：分享到微信朋友圈)
//     */
//    private void wechatShare(final int flag) {
//
//        //这里替换一张自己工程里的图片资源
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                try {
//                    WXWebpageObject webpage = new WXWebpageObject();
//                    webpage.webpageUrl = shareurl;
//
//                    WXMediaMessage msg = new WXMediaMessage(webpage);
//                    msg.title = sharetitle;
//                    msg.description = sharecontent;
//                    Bitmap thumb = imageLoader.loadImageSync(shareimage);
//                    msg.setThumbImage(thumb);
//                    SendMessageToWX.Req req = new SendMessageToWX.Req();
//                    req.transaction = String.valueOf(System.currentTimeMillis());
//                    req.message = msg;
//                    req.scene = flag == 0 ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline;
//                    wxApi.sendReq(req);
//                    System.out.println("@@@@@==!!" + req.toString());
//                } catch (Exception e) {
//                    System.out.println("@@@@@=="+e.toString());
//                    e.printStackTrace();
//                }
//            }
//        }).start();
//    }
//    private WebpageObject getWebpageObj() {
//        WebpageObject mediaObject = new WebpageObject();
//        mediaObject.actionUrl = shareurl;
//        mediaObject.identify = shareId;
//        mediaObject.title = sharetitle;
//        mediaObject.description = sharecontent;
//        Bitmap bmp = imageLoader.loadImageSync(shareimage);
//
//        mediaObject.setThumbImage(bmp);
//        return mediaObject;
//    }
//    @Override
//    protected void onResume() {
//        //  initData();
//        super.onResume();
//        if(shareType == 1 && StringTools.shareback == 101){
//            shareSuccese(new MyHandler(), getApplication());
//            shareType = 10;
//            StringTools.shareback = 100;
//        }
//        else if(shareType == 3 && StringTools.shareback == 103){
//            shareSuccese(new MyHandler(), getApplication());
//            shareType = 10;
//            StringTools.shareback = 100;
//        }else if(shareType == 2 && StringTools.shareback == 101){
//            shareSuccese(new MyHandler(), getApplication());
//            shareType = 10;
//            StringTools.shareback = 100;
//        }
//    }
//    class MyHandler extends Handler{
//        @Override
//        public void handleMessage(Message msg) {
//            super.handleMessage(msg);
//            String data = (String)msg.obj;
//            shareover(data);
//        }
//    }
//    private void shareover(String sharemsg) {
//        final DialogView dialogView = new DialogView(ShareActivity.this, R.layout.dialogview_duihuan_address, R.style.pager_dialog, 1, sharemsg);
//        dialogView.setOnBtnClickListener(new DialogView.OnBtnClickListener() {
//            @Override
//            public void onclick(int i) {
//                if (i == 0) {
//                    dialogView.cancel();
//                }
//            }
//        });
//        dialogView.show();
//    }
//    public void shareSuccese(final Handler handler, final Context context) {
//
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//
//                RestTemplate restTemplate = new RestTemplate();
//                HttpHeaders httpHeaders = new HttpHeaders();
//
//                // 取sessionKey
//                ACache mCache = ACache.get(context);
//
//                String sessionKeyLogin = mCache.getAsString("sessionKeyLogin");
//                // 设置请求头
//                httpHeaders.set("Cookie", "JSESSIONID=" + sessionId);
//                // 把请求头放在请求实体里
//
//                HttpEntity<?> requestEntity = new HttpEntity<Object>(httpHeaders);
//
//                final ResponseEntity<Shareover> shareoverUi = restTemplate.exchange("http://app.mlzmall.com/api/promotion/sharePromotionReturn?promotionId=" + promotionId, HttpMethod.GET, requestEntity, Shareover.class);
//                sharemsg = shareoverUi.getBody().getMsg();//分享成功后的结果显示
//                Message message = handler.obtainMessage();
//                message.obj = sharemsg;
//                handler.sendMessage(message);
//            }
//        }).start();
//
//    }
//    @Override
//    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//        if(mTencent != null){
//            mTencent.onActivityResultData(requestCode, resultCode, data,baseUiListener);
//        }
//    }
}
